package ${package.ServiceImpl};

import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import io.github.talelin.latticy.dto.${table.entityPath}.CreateOrUpdate${entity}DTO;
import ${package.Entity}.${entity}DO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;

/**
* @author vvboy
*/
@Service
public class ${table.serviceImplName} implements ${table.serviceName} {

    @Autowired
    private ${table.mapperName} ${table.entityPath}Mapper;

    @Override
    public boolean create${entity}(CreateOrUpdate${entity}DTO validator) {
        ${entity}DO ${table.entityPath} = new ${entity}DO();
        BeanUtils.copyProperties(validator, ${table.entityPath});
        return ${table.entityPath}Mapper.insert(${table.entityPath}) > 0;
    }


    @Override
    public boolean update${entity}(${entity}DO ${table.entityPath}, CreateOrUpdate${entity}DTO validator) {
        BeanUtils.copyProperties(validator, ${table.entityPath});
        return ${table.entityPath}Mapper.updateById(${table.entityPath}) > 0;
    }

    @Override
    public ${entity}DO getById(Integer id) {
        return ${table.entityPath}Mapper.selectById(id);
    }

    @Override
    public List<${entity}DO> findAll() {
        return ${table.entityPath}Mapper.selectList(null);
    }

    @Override
    public boolean deleteById(Integer id) {
        return ${table.entityPath}Mapper.deleteById(id) > 0;
    }

}
